#-*- coding:gbk -*-
'''
Created on 2012-7-23

@author: xxy
'''

import time

class WorldTimer(object):
    def __init__(self, callback_func, period):
        self.m_callback_func = callback_func
        self.m_period = period
        self.m_expire = time.time() + self.m_period  
        
    def getExpire(self):
        return self.m_expire
    
    def update(self, now_time):
        #print 'timer update'
        expire = self.m_expire - now_time
        #print expire
        if expire <= 0:
            self.m_callback_func(self.m_period)
            self.m_expire += self.m_period 
            return True
        else:
            return False